<?php

//This is the directory where images will be saved
$target = "../files/";
$target = $target . basename( $_FILES['file']['name']);
$path = "../files/";
$rpath = "files/";

//This gets all the other information from the form
$name = $_POST['user_id'];
$filename = $_POST['filename'];
$description = $_POST['description'];
$pic = ($_FILES['file']['name']);




// Connects to your Database
include "../scripts/connectDB.php";

//Writes the information to the database
mysql_query("INSERT INTO files (user_id,filename,description,path)
VALUES ('$name', '$filename', '$description', '$rpath$pic')") ;

//Writes the photo to the server

if ((($_FILES["file"]["type"] == "application/x-compressed")
|| ($_FILES["file"]["type"] == "application/x-zip-compressed")
|| ($_FILES["file"]["type"] == "multipart/x-zip")
|| ($_FILES["file"]["type"] == "application/x-zip")
|| ($_FILES["file"]["type"] == "application/octet-stream")
|| ($_FILES["file"]["type"] == "application/x-compress")
|| ($_FILES["file"]["type"] == "application/zip"))
&& ($_FILES["file"]["size"] < 9999999999))


  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("TEMP/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "$path" . $_FILES["file"]["name"]);
      echo "Stored in: " . "$path" . $_FILES["file"]["name"];
	  
	  
	  }
    }
  }
else
  {
  echo "Invalid file";
  }

header("Location: ../adminupload.php")
?>